<script setup lang="ts">
import { ref } from 'vue'
import {ElMessage} from "element-plus";
import axiosUtil from "../../axios-util/axios-util.ts";

const searchText = ref('')
const sourceContent = ref('')
const keywords = ref('')
const generatedContent = ref('')

const generateSimilarContent = () => {
  // TODO: 实现生成逻辑
  console.log('生成同款文案')
}

const getGeneratedContent = async () =>{
   if(searchText.value){
     const response = await axiosUtil.post('api/opencz/tiquwennan3', {
       url:searchText.value
     })
     if(response.data.code===1){
       //这里是成功的逻辑，但是目前没有成功，所以不知道怎么写
     }else{
       ElMessage.error(response.data.msg)
     }
   }else {
     ElMessage.error('请先输入分享链接')
   }
}
</script>

<template>
  <div class="follow-note">
    <div class="container">
      <div class="header">
        <div class="section-title">
          <div class="number-circle">1</div>
          <h1 class="title">获取文案</h1>
        </div>
        <div class="search-box">
          <input v-model="searchText" type="text" placeholder="请输入分享链接" />
          <button class="search-btn" @click="getGeneratedContent">提取文案</button>
        </div>
      </div>

      <div class="content">
        <div class="source-section">
          <div class="section-title">
            <div class="number-circle">2</div>
            <h2 class="title">获取的文案</h2>
          </div>
          <textarea
            v-model="sourceContent"
            placeholder="请输入内容"
            rows="10"
            class="input-area"
          ></textarea>
          <textarea
            v-model="keywords"
            class="keywords-input"
            placeholder="请输入关键词"
            rows="2"
          ></textarea>
          <button
            class="generate-btn"
            @click="generateSimilarContent"
          >✨ 生成同款文案</button>
        </div>

        <div class="result-section">
          <div class="section-title">
            <div class="number-circle">3</div>
            <h2 class="title">新生成的文案</h2>
          </div>
          <textarea
            v-model="generatedContent"
            placeholder="请输入内容"
            rows="20"
            class="output-area"
          ></textarea>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.follow-note {
  width: 100%;
  height: 100%;
  padding: 20px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
}

.container {
  display: flex;
  flex-direction: column;
  gap: 20px;
  flex: 1;
  width: 100%;
  min-height: 0;
}

.header {
  margin-bottom: 20px;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 15px;
}

.number-circle {
  width: 24px;
  height: 24px;
  background-color: #7c4dff;
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: bold;
}

.title {
  font-size: 20px;
  color: #333;
  margin: 0;
  font-weight: 500;
}

.search-box {
  display: flex;
  gap: 10px;
}

.search-box input {
  flex: 1;
  padding: 12px;
  border: 1px solid #dcdfe6;
  border-radius: 8px;
  background-color: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
}

.search-box input:hover {
  background-color: rgba(255, 255, 255, 0.2);
  border-color: #7c4dff;
}

.search-box input:focus {
  background-color: rgba(255, 255, 255, 0.2);
  border-color: #7c4dff;
  outline: none;
}

.search-btn {
  padding: 12px 24px;
  background-color: #7c4dff;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
}

.search-btn:hover {
  background-color: #6c3fff;
}

.content {
  display: flex;
  gap: 20px;
  flex: 1;
}

.source-section, .result-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.input-area, .output-area {
  width: 100%;
  padding: 15px;
  border: 1px solid #dcdfe6;
  border-radius: 8px;
  resize: none;
  background-color: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  box-sizing: border-box;
}

.input-area {
  flex: 1;
  min-height: 150px;
}

.output-area {
  flex: 1;
  min-height: 200px;
}

.input-area:hover, .output-area:hover {
  background-color: rgba(255, 255, 255, 0.2);
  border-color: #7c4dff;
}

.input-area:focus, .output-area:focus {
  background-color: rgba(255, 255, 255, 0.2);
  border-color: #7c4dff;
  outline: none;
}

.keywords-input {
  width: 100%;
  padding: 15px;
  border: 1px solid #dcdfe6;
  border-radius: 8px;
  background-color: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  box-sizing: border-box;
  resize: none;
  min-height: 70px;
}

.keywords-input:hover {
  background-color: rgba(255, 255, 255, 0.2);
  border-color: #7c4dff;
}

.keywords-input:focus {
  background-color: rgba(255, 255, 255, 0.2);
  border-color: #7c4dff;
  outline: none;
}

.generate-btn {
  width: 100%;
  padding: 12px;
  background-color: #7c4dff;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
}

.generate-btn:hover {
  background-color: #6c3fff;
}

.footer-hint {
  text-align: center;
  color: #666;
  font-size: 14px;
  padding-top: 20px;
}
</style>
